{layout name="common/base" }
<div class="layui-form layuimini-form">
    <input type="text" hidden value="<?php echo $data['id'];?>" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入商品名" value="<?php echo $data['name'];?>" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">分类</label>
        <div class="layui-input-inline">
            <select name="category_id">
                <?php foreach ($categoryData as $k => $v): ?>
                <?php if($data['category_id'] == $v['id']):?>
                <option value="<?php echo $v['id']; ?>" selected="selected"><?php echo $v['name']; ?></option>
                <?php else:?>
                <option value="<?php echo $v['id']; ?>"><?php echo $v['name']; ?></option>
                <?php endif;?>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封面图</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload_btn">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <div><tip>上传图片正方形</tip></div>
            <img id="previewImg" width="100px" height="75px" src="<?php echo $data['thumb'];?>">
            <input id="upload_image" name="thumb" type="hidden" multiple="true" value="<?php echo $data['thumb'];?>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内页Banner图</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload_btn1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <div><tip>上传图片正方形</tip></div>
            <img id="previewImg1" width="150px" height="75px" src="<?php echo $data['thumbbanner'];?>">
            <input id="upload_image1" name="thumbbanner" type="hidden" multiple="true" value="<?php echo $data['thumbbanner'];?>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="required" lay-reqtext="价格为0，则表示免费" placeholder="请输入价格" value="<?php echo $data['price'];?>" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">简要</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入简要" class="layui-textarea" name="summary"><?php echo $data['summary'];?></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">推荐</label>
        <div class="layui-input-block">
            <input type="radio" name="is_recommend" value="0" title="否" <?php if($data['is_recommend'] == 0) echo 'checked="checked"';?>>
            <input type="radio" name="is_recommend" value="1" title="推荐" <?php if($data['is_recommend'] == 1) echo 'checked="checked"';?>>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">热门</label>
        <div class="layui-input-block">
            <input type="radio" name="is_hot" value="0" title="否" <?php if($data['is_hot'] == 0) echo 'checked="checked"';?>>
            <input type="radio" name="is_hot" value="1" title="热门" <?php if($data['is_hot'] == 1) echo 'checked="checked"';?>>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="下架" <?php if($data['status'] == 0) echo 'checked="checked"';?>>
            <input type="radio" name="status" value="1" title="上架" <?php if($data['status'] == 1) echo 'checked="checked"';?>>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">浏览量（假数据）</label>
        <div class="layui-input-block">
            <input type="number" name="fakenum" value="<?php echo $data['fakenum'];?>" title="fakenum">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sort" placeholder="请输入排序" value="<?php echo $data['sort'];?>" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="__PUBLIC__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/commons.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/image.js" charset="utf-8"></script>
<script type="text/javascript">
    var url = '/admin/Product/edit';
    add_edit(url);
    layui.use('upload', function(){
        var $ = layui.jquery,
            upload = layui.upload,
            upload1 = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_btn',
            url: '/admin/Image/upload', //改成您自己的上传接口 /common/image/upload
            before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    //$('#previewImg').css("height", 100);
                    //$('#previewImg').css("width", 100);
                    $('#previewImg').attr('src', result); //图片链接（base64）
                });
            },done: function(obj){
                //code: 1
                //data:
                //    filePath: "/upload/image20200201\a931d611ed438d3df5817608f557662d.png"
                //msg: "success"
                if(obj.status > 0){ //上传成功
                    $("#upload_image").attr("value", obj.data.path);
                }else{
                    return layer.msg('上传失败');
                }
            },error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        var uploadInst1 = upload1.render({
            elem: '#upload_btn1',
            url: '/admin/Image/upload', //改成您自己的上传接口 /common/image/upload
            before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    //$('#previewImg').css("height", 100);
                    //$('#previewImg').css("width", 100);
                    $('#previewImg1').attr('src', result); //图片链接（base64）
                });
            },done: function(obj){
                //code: 1
                //data:
                //    filePath: "/upload/image20200201\a931d611ed438d3df5817608f557662d.png"
                //msg: "success"
                if(obj.status > 0){ //上传成功
                    $("#upload_image1").attr("value", obj.data.path);
                }else{
                    return layer.msg('上传失败');
                }
            },error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst1.upload();
                });
            }
        });
    });
</script>
